// pages/practiceList/practiceList.js
let app = getApp();
var util = require("../../utils/util.js");
var siteinfo = require('../../siteinfo.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        allList: [],
        selectName: '',
        selectList: [],
        index: 0,
        selectId: '',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getSelByAll()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
     onShow() {
         
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },
    bindPickerChange: function (e) {
        this.setData({
            index: e.detail.value,
            selectId: this.data.selectList[e.detail.value].id,
            selectName: this.data.selectList[e.detail.value].name,
        })
        this.handleSelPaperList()
        console.log('picker发送选择改变，携带值为', this.data.selectName)
    },
    getSelByAll: function () {
        var _this = this
        app._post_form(siteinfo.yysSelByAll, {}, function (result) {
            _this.setData({
                selectList: result.data,
                selectName:result.data[0].name,
                selectId:result.data[0].id,
            });
            _this.handleSelPaperList()
        })
     
    },
    handleSelPaperList() {
        var that = this
        let token = wx.getStorageSync('token');
        wx.request({
            url: siteinfo.siteroot3 + 'jzApi/jzPaperPracticeRecord/selPaperList',
            header: {
                'Authorization': token,
                'content-type': 'application/json'
            },
            data: {
                id: this.data.selectId
            },
            method: 'GET',
            success: function (res) {
                that.setData({
                    allList: res.data.data
                });
            }
        });
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})